package com.cn.pw.jdbc;

import java.sql.DriverManager;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class DBTest {
	 public static void main(String[] args) { 
         String driver = "com.mysql.jdbc.Driver"; 
         String url = "jdbc:mysql://localhost:3306/test"; 
         String user = "ZhuJun"; 
         String password = "123456"; 
         try { 
              Class.forName(driver); 
              Connection conn = (Connection) DriverManager.getConnection(url, user, password);

              if(!conn.isClosed()) 
                   System.out.println("数据库连接成功！"); 
              conn.close(); 
         } 
         catch(ClassNotFoundException e) { 
              System.out.println("找不到驱动程序"); 
              e.printStackTrace(); 
         } 
         catch(SQLException e) { 
              e.printStackTrace(); 
         } 
    }
}
